const express = require("express");
const router = express.Router();

// 导入控制器
const CostStatisticsController = require("../controller/CostStatisticsController");
const costStatisticsController = new CostStatisticsController();

// 引入权限检查中间件
const checkRoleMiddleware = require("../middleware/checkRoleMiddleware");

// 允许所有权限用户查看
const COST_STATISTICS_ROLES = {
  READ: [1, 2, 3],
};

// 获取就餐人数
// GET /costStatistics/diningCount?startDate=YYYY-MM-DD&endDate=YYYY-MM-DD
router.get(
  "/diningCount",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getDiningCount(req, res);
  }
);

// 按分类统计出库数量
// GET /costStatistics/categoryOutboundQuantityStat?stallIds=1,2&startDate=...
router.get(
  "/categoryOutboundQuantityStat",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getCategoryOutboundQuantityStat(req, res);
  }
);

// 按分类和档口统计出库总金额
// GET /costStatistics/purchaseCostAnalysis?stallIds=1,2&startDate=...
router.get(
  "/purchaseCostAnalysis",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getPurchaseCostAnalysis(req, res);
  }
);

// 按档口统计总金额
// GET /costStatistics/stallCostRatioStat?stallIds=1,2&startDate=...
router.get(
  "/stallCostRatioStat",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getStallCostRatioStat(req, res);
  }
);

// 按分类统计食材种类数量
// GET /costStatistics/goodsCountByCategoryStat
router.get(
  "/goodsCountByCategoryStat",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getGoodsCountByCategoryStat(req, res);
  }
);

// 每日总成本统计
// GET /costStatistics/dailyTotalCostStat?stallIds=1,2&startDate=...
router.get(
  "/dailyTotalCostStat",
  checkRoleMiddleware(COST_STATISTICS_ROLES.READ),
  (req, res) => {
    return costStatisticsController.getDailyTotalCostStat(req, res);
  }
);

module.exports = router;
